{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "load Subject_A_Train.mat;\n",
    "window=240; % window after stimulus (1s)\n",
    "\n",
    "responses_train = zeros(12, 15, 240, 64, 85);\n",
    "is_stimulate = zeros(12, 15, 85);\n",
    "\n",
    "% convert to double precision\n",
    "Signal=double(Signal);\n",
    "Flashing=double(Flashing);\n",
    "StimulusCode=double(StimulusCode);\n",
    "StimulusType=double(StimulusType);\n",
    "\n",
    "% for each character epoch\n",
    "for epoch=1:size(Signal,1)\n",
    "    % get reponse samples at start of each Flash\n",
    "    rowcolcnt=ones(1,12);\n",
    "    block = 1;\n",
    "    for n=2:size(Signal,2)\n",
    "        if Flashing(epoch,n)==0 && Flashing(epoch,n-1)==1\n",
    "            rowcol=StimulusCode(epoch,n-1);\n",
    "            responses_train(rowcol,rowcolcnt(rowcol),:,:,epoch)=Signal(epoch,n-24:n+window-25,:);\n",
    "            rowcolcnt(rowcol)=rowcolcnt(rowcol)+1;\n",
    "            if StimulusType(epoch, n-1) == 1\n",
    "                is_stimulate(rowcol, block, epoch) = 1;               \n",
    "            end\n",
    "        end\n",
    "        if mod(n, 504) == 0\n",
    "            block = block + 1;\n",
    "        end\n",
    "    end\n",
    "end\n",
    "\n",
    "\n",
    "responses_train = reshape(mean(responses_train, 2), 12, 240, 64, 85);\n",
    "is_stimulate_train = uint8(reshape(mean(is_stimulate, 2), 12, 85));"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "clear all;  \n",
    "clc;\n",
    "temp=zeros(12,85,64,240);\n",
    "\n",
    "load ('data_train_A.mat');\n",
    "data = [];\n",
    "label = [];\n",
    "\n",
    "temp=permute(responses_train,[2,1,3,4]);\n",
    "data_temp1=squeeze(temp(:,:,3,:));\n",
    "data_temp2=squeeze(temp(:,:,5,:));\n",
    "data_temp3=squeeze(temp(:,:,9,:));\n",
    "data_temp4=squeeze(temp(:,:,11,:));\n",
    "data_temp5=squeeze(temp(:,:,13,:));\n",
    "data_temp6=squeeze(temp(:,:,22,:));\n",
    "data_temp7=squeeze(temp(:,:,24,:));\n",
    "data_temp8=squeeze(temp(:,:,34,:));\n",
    "data_temp9=squeeze(temp(:,:,51,:));\n",
    "data_temp10=squeeze(temp(:,:,56,:));\n",
    "data_temp11=squeeze(temp(:,:,60,:));\n",
    "\n",
    "responses_train=[data_temp1;data_temp2;data_temp3;data_temp4;data_temp5;data_temp6;data_temp7;data_temp8;data_temp9;data_temp10;data_temp11];\n",
    "\n",
    "\n",
    "responses_train=permute(responses_train,[2,3,1]);\n",
    "responses_train=reshape(responses_train,12,85,2640);\n",
    "for i=1:12\n",
    "    for j=1:85    \n",
    "        data = [data; responses_train(i, j,:)];\n",
    "        label = [label; is_stimulate_train(i, j)];\n",
    "    end\n",
    "end\n",
    "\n",
    "data = reshape(data, 1020, 2640);\n",
    "\n",
    "Model_A= fitcsvm(data,label);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Matlab [conda env:jmatlab]",
   "language": "matlab",
   "name": "conda-env-jmatlab-matlab"
  },
  "language_info": {
   "codemirror_mode": "octave",
   "file_extension": ".m",
   "help_links": [
    {
     "text": "MetaKernel Magics",
     "url": "https://github.com/calysto/metakernel/blob/master/metakernel/magics/README.md"
    }
   ],
   "mimetype": "text/x-octave",
   "name": "matlab",
   "version": "0.16.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
